package life.mahu.community.provider;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.fileupload.FileItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

//@Service
//@Slf4j
public class QQCloudProvider {
//    @Autowired
//    private RestTemplate restTemplate;
//
//    @Value("${upload.url}")
//    private String uploadUrl;
//
//    public String upload(MultipartFile file) throws IOException {
//
//
//        MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>();
//        HttpHeaders headers = new HttpHeaders();
//        headers.setContentType(MediaType.MULTIPART_FORM_DATA);
//        HttpHeaders pictureHeader = new HttpHeaders();
//        pictureHeader.setContentType(MediaType.parseMediaType(file.getContentType()));
//        //如果是用spring 的MultipartFile接受，则加入下面这行， 去个随机文件名
//        pictureHeader.setContentDispositionFormData("file", "image" + ".PNG");
//        HttpEntity<byte[]> picturePart = new HttpEntity<>(
//                file.getBytes(), pictureHeader);
//        multipartRequest.add("file", picturePart);
//        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>
//                (multipartRequest, headers);
//        ResponseEntity<String> result = restTemplate.postForEntity(uploadUrl,requestEntity,String.class);
//
//        String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);
//
//        return uploadUrl.concat(result.getBody()) + "." +extName;
//    }


}
